import apiList from 'apiList.js' //  引入apiList.js文件

const apiRequest = (url, method, data, header) => { //接收所需要的参数，如果不够还可以自己自定义参数
    let promise = new Promise(function (resolve, reject) {
        wx.request({
            url: url,
            data: data ? data : {},
            method: method,
            header: header ? header : {
                "Content-Type": "application/json"
            },
            success: function (res) {
                if (res.data.status == 401) {
                    wx.showToast({
                        title: res.data.msg,
                        icon: 'none',
                        duration: 1500,
                        complete: function (res) {
                            wx.setStorageSync('islogin', false)
                            setTimeout(function () {
                                wx.switchTab({
                                    url: '/pages/mine/mine',
                                })
                            }, 1500)
                            return
                        }
                    })
                }
                //接口调用成功
                resolve(res); //根据业务需要resolve接口返回的json的数据
            },
            fail: function (res) {
                // fail调用接口失败
                reject({
                    errormsg: '网络错误,请稍后重试',
                    code: -1
                });
            }
        })
    });
    return promise; //注意，这里返回的是promise对象
}

let GetToken = (data) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetToken, 'GET', data))
    })
}

let GetUserMobileInfo = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetUserMobileInfo, 'POST', data, header))
    })
}

let GetUserMobileInfoNew = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetUserMobileInfoNew, 'POST', data, header))
    })
}

let SaveUserInfo = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.SaveUserInfo, 'POST', data, header))
    })
}

let GetShopList = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetShopList, 'GET', data, header))
    })
}

let GetShopModel = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetShopModel, 'GET', data, header))
    })
}

let GetNewsTop = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetNewsTop, 'GET', data, header))
    })
}

let GetNewsList = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetNewsList, 'GET', data, header))
    })
}

let GetNewsModel = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetNewsModel, 'GET', data, header))
    })
}

let Getuserinfo = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.Getuserinfo, 'GET', data, header))
    })
}

let GetTypeList = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetTypeList, 'GET', data, header))
    })
}

let GetTypeListNew = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetTypeListNew, 'GET', data, header))
    })
}

let GetGoodsByGroups = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetGoodsByGroups, 'GET', data, header))
    })
}

let PostScorePhoto = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.PostScorePhoto, 'POST', data, header))
    })
}

let GetScoreLogList = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetScoreLogList, 'GET', data, header))
    })
}

let SaveUserInfoByScore = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.SaveUserInfoByScore, 'POST', data, header))
    })
}

let PostShareArticleScore = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.PostShareArticleScore, 'POST', data, header))
    })
}

let PostSignInScore = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.PostSignInScore, 'POST', data, header))
    })
}

let GetHuoDongList = (data) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetHuoDongList, 'GET', data))
    })
}

let GetHtmlList = (data) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetHtmlList, 'GET', data))
    })
}

let PostHuoDong = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.PostHuoDong, 'POST', data, header))
    })
}

let PostScoreGood = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.PostScoreGood, 'POST', data, header))
    })
}

let PostCodeScoreGood = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.PostCodeScoreGood, 'POST', data, header))
    })
}

let VerifyHuoDongByCode = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.VerifyHuoDongByCode, 'POST', data, header))
    })
}

let PostNewsHits = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.PostNewsHits, 'POST', data, header))
    })
}

let LuckyDraw = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.LuckyDraw, 'POST', data, header))
    })
}

let GetHuoDongLogList = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetHuoDongLogList, 'GET', data, header))
    })
}

let GetGoodLogList = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetGoodLogList, 'GET', data, header))
    })
}

let GetGoodList = (data) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetGoodList, 'GET', data))
    })
}

let GetUserTaskFlag = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetUserTaskFlag, 'GET', data, header))
    })
}

let GetVerifyGoodLogList = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetVerifyGoodLogList, 'GET', data, header))
    })
}

let GetVerifyHuoDongLogList = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetVerifyHuoDongLogList, 'GET', data, header))
    })
}

let GetIndexHtmlList = (data) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetIndexHtmlList, 'GET', data))
    })
}

let SendMessageByGood = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.SendMessageByGood, 'GET', data, header))
    })
}

let GetHuoDongListNoPage = (data) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetHuoDongListNoPage, 'GET', data))
    })
}

let GetPriceByCarNo = (data) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetPriceByCarNo, 'GET', data))
    })
}

let GetPayInfo = (data) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetPayInfo, 'GET', data))
    })
}

let InquiryNotify = () => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.InquiryNotify, 'POST'))
    })
}

let PostOrderReturn = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.PostOrderReturn, 'POST', data, header))
    })
}

let PostHuoDongCangCi = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.PostHuoDongCangCi, 'POST', data, header))
    })
}

let Save = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.Save, 'POST', data, header))
    })
}

let OpenInvoiceHuoDong = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.OpenInvoiceHuoDong, 'POST', data, header))
    })
}

let OpenInvoiceShop = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.OpenInvoiceShop, 'POST', data, header))
    })
}

let Delete = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.Delete, 'POST', data, header))
    })
}

let GetInvoice = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetInvoice, 'GET', data, header))
    })
}

let GetInvoices = (data, header) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.GetInvoices, 'GET', data, header))
    })
}

let GetHuoDongCangCiDetail = (data, header) => {
  return new Promise((resolve, reject) => {
      resolve(apiRequest(apiList.GetHuoDongCangCiDetail, 'GET', data, header))
  })
}

let AccoutLogin = (data) => {
    return new Promise((resolve, reject) => {
        resolve(apiRequest(apiList.AccoutLogin, 'POST', data))
    })
}

//最后需要将具体调用的函数暴露出，给具体业务调用

export default {
    GetToken: GetToken,
    GetUserMobileInfo: GetUserMobileInfo,
    SaveUserInfo: SaveUserInfo,
    GetShopList: GetShopList,
    GetShopModel: GetShopModel,
    GetNewsTop: GetNewsTop,
    GetNewsList: GetNewsList,
    GetNewsModel: GetNewsModel,
    Getuserinfo: Getuserinfo,
    GetTypeList: GetTypeList,
    PostScorePhoto: PostScorePhoto,
    GetScoreLogList: GetScoreLogList,
    SaveUserInfoByScore: SaveUserInfoByScore,
    PostShareArticleScore: PostShareArticleScore,
    PostSignInScore: PostSignInScore,
    GetHuoDongList: GetHuoDongList,
    GetHtmlList: GetHtmlList,
    PostHuoDong: PostHuoDong,
    GetHuoDongLogList: GetHuoDongLogList,
    GetGoodLogList: GetGoodLogList,
    GetGoodList: GetGoodList,
    PostScoreGood: PostScoreGood,
    PostCodeScoreGood: PostCodeScoreGood,
    GetUserTaskFlag: GetUserTaskFlag,
    GetIndexHtmlList: GetIndexHtmlList,
    LuckyDraw: LuckyDraw,
    GetVerifyGoodLogList: GetVerifyGoodLogList,
    PostNewsHits: PostNewsHits,
    VerifyHuoDongByCode: VerifyHuoDongByCode,
    GetVerifyHuoDongLogList: GetVerifyHuoDongLogList,
    SendMessageByGood: SendMessageByGood,
    GetHuoDongListNoPage: GetHuoDongListNoPage,
    GetTypeListNew: GetTypeListNew,
    GetGoodsByGroups: GetGoodsByGroups,
    GetPriceByCarNo: GetPriceByCarNo,
    GetPayInfo: GetPayInfo,
    InquiryNotify: InquiryNotify,
    PostOrderReturn: PostOrderReturn,
    PostHuoDongCangCi: PostHuoDongCangCi,
    Save: Save,
    OpenInvoiceHuoDong: OpenInvoiceHuoDong,
    OpenInvoiceShop: OpenInvoiceShop,
    GetInvoice: GetInvoice,
    GetInvoices: GetInvoices,
    Delete: Delete,
    AccoutLogin: AccoutLogin,
    GetUserMobileInfoNew: GetUserMobileInfoNew,
    GetHuoDongCangCiDetail: GetHuoDongCangCiDetail
}